package cn.com.bluemoon.daps.domp.api.param;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户角色信息
 *
 * @author Jarod.Kong
 * @date 2021/7/23 13:38
 */
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class UserDto implements Serializable {
    private static final long serialVersionUID = 1L;
    /* 用户名、手机号码、用户id，用户描述、状态*/
    private String user_name, mobile, id, user_des, status, zw;
    /* 创建时间 */
    private Long create_date;
    /* 角色 */
    private List<RoleDto> roles;

    public static UserDto fromObj(JSONObject jsonObject) {
        if (jsonObject == null) {
            return null;
        }
        UserDto userDto = JSONObject.toJavaObject(jsonObject, UserDto.class);
        return userDto;
    }

    public static List<UserDto> fromObjs(JSONArray array) {
        if (array == null) {
            return Collections.emptyList();
        }
        return array.stream().map(o -> fromObj((JSONObject) o)).collect(Collectors.toList());
    }

    @Override
    public String toString() {
        return ReflectionToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
    }
}

